<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<title>layui后台布局</title>
<script type="text/javascript" th:src="@{/js/jquery-2.1.0.js}"></script>
<script type="text/javascript" th:src="@{/layui/layui.js}"
	charset="utf-8"></script>
<script type="text/javascript" th:src="@{/js/common.js}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/js/forbid/forbid.js}"></script>
<link th:href="@{/layui/css/layui.css}" rel="stylesheet" />
<link th:href="@{/css/reset.css}" rel="stylesheet" />
</head>
<body>
	<div class="padding15">
		<form class="layui-form" action="" method="post" id="layForm">
			<table class="layui-table">
				<colgroup>
					<col width="150">
					<col width="150">
					<col width="200">
					<col>
				</colgroup>
				<thead>
					<tr>
						<th>userName</th>
						<th>account</th>
						<th>check</th>
					</tr>
				</thead>
				<tbody>
					<tr th:each="user : ${users}">
						<td th:text="${user.name}">Onions</td>
						<td th:text="${user.account}">2.41</td>
						<td ><input type="checkbox" th:attr="data-id = ${user.id}" lay-skin="primary" th:checked="${user.isChecked}"  /></td>
					</tr>
				</tbody>
			</table>
			<div class="layui-form-item text-center">
                <button class="layui-btn" lay-submit lay-filter="btnSave">保存</button>
                <button class="layui-btn layui-btn-primary" onclick="closeThisPop();">取消</button>
            </div>
		</form>
		
	</div>
	<script type="text/javascript">
	layui.use('form', function(){
		  var form = layui.form;
		  
		  //监听提交
		   form.on('submit(btnSave)', function(data){
			   var ids = [];
				var target = $("input").find("checked");
				$("input:checked").each(function() {
					//var id = $(this).parent().parent().children(":first").html();
					var id = $(this).data("id");
					ids.push(id);
				});
				$.ajax({
                    type: 'POST',
                    url: "/role/users",
                    data: {
                    	id:GetQueryString("id"),
                    	userIds:ids.toString()
                    },
                    traditional: true,
                    success: function (data) {
                    	console.log(data);
                        if (data.status) {
                            layWin.showMsg(data.message, 1);
                            //当你在iframe页面关闭自身时
                            closeThisPop();
                            //回调主页面刷新
                            parent.search();
                        } 
                    },
                    error: function (msg) {
                        layWin.showMsg(msg, 5);
                    }, complete: function (data) {
                    }
                });
		    return false;
		  }); 
		});
	
	</script>
</body>
</html>